package kr.hkit.powerjava.chapter17;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;

import java.awt.BorderLayout;

import javax.swing.SwingConstants;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ImageLabelSwingCom extends JPanel implements ActionListener {
	private JLabel lblImage;
	private JButton btn;

	/**
	 * Create the panel.
	 */
	public ImageLabelSwingCom() {

		initialize();
	}
	private void initialize() {
		setLayout(new BorderLayout(0, 0));
		
		lblImage = new JLabel("이미지를 보려면 아래 버튼을 누르세요");
		lblImage.setHorizontalAlignment(SwingConstants.CENTER);
		add(lblImage, BorderLayout.CENTER);
		
		btn = new JButton("이미지레이블");
		btn.addActionListener(this);
		add(btn, BorderLayout.SOUTH);
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == btn) {
			actionPerformedBtnNewButton(e);
		}
	}
	protected void actionPerformedBtnNewButton(ActionEvent e) {
		if(lblImage.getIcon()==null){
			ImageIcon icon = new ImageIcon("c.PNG");
			lblImage.setIcon(icon);
			lblImage.setText(null);
		}else{
			lblImage.setIcon(null);
			lblImage.setText("이미지를 보려면 아래 버튼을 누르시오");
		}
	}
}
